package com.jason.methodextend

import kotlin.reflect.KProperty


fun main() {
    println("1111111111111111")
//    val people = People()
//    println("zyh" + "onCreate: ${people.email}")
//    people.email = "222@qq.com"
//    println("zyh" + "onCreate: ${people.email}")


    val r0: Int ="Derry".let {
        true
        it.length
    }
    println("run r1  : "+r0)

    val r1 : Int ="Derry".run {
        true
        length
    }
    println("run r1  : "+r1)
    val r2 :String= 123.run {
        "999"
//        "【${this}】"
    }
        println("run r2  : "+r2)



}


//by约定能正常使用的方法
class ProduceEmail() {

    private val emails = arrayListOf("111@qq.com")

    //对应于被委托属性的get函数
    operator fun getValue(people: People, property: KProperty<*>): String {
        println("zyh" + "getValue: 操作的属性名是 ${property.name}")
        return emails.last()
    }

    //对于被委托属性的get函数
    operator fun setValue(people: People, property: KProperty<*>, s: String) {
        emails.add(s)
    }

}

class People {
    val name: String? = null
    var age: Int = 0
    val isAbove18: Boolean = false

    //委托属性
    var email: String by ProduceEmail()
}